﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserSection.aspx.cs" Inherits="School_Report_UserSection" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>分数段设置</title>

<link href="../../Common/css/main.css" rel="stylesheet" type="text/css" />
<!--分数段设置控件-->

<script type="text/javascript" src="../../Common/Js/jquery.js"></script>

<script type="text/javascript" src="../../Common/Js/common.js"></script>

<script type="text/javascript" src="../../Common/Js/msg.js"></script>
<script type="text/javascript">
    var doThis=null;
    function SetDoWhat(fun)
    {
        doThis = fun;
    }
    
    function onSchange()
    {
        var subjectSelect = document.getElementById('subjectSelect');
        var value = subjectSelect.options[subjectSelect.selectedIndex].value;
        var typeid = document.getElementById('typeid');
        var btnBind = document.getElementById('btnBind');
        if(typeid!=null && btnBind!=null)
        {
            typeid.value = value;
            btnBind.click();
        }
        settingChange = false;
        SetDoWhat(null);
    }

    function OnclosePage(obj)
    {
        showConfirmBox("提示", "是否要保存设置?", SaveSettings, null,obj);
    }

    var settingChange = false;
    //选项变更
    function onSubjectSelect(index)
    {
        if(index>=0)
        {
            if(settingChange==true)
            {
                SetDoWhat(onSchange);
                showConfirmBox("提示", "是否要保存设置?", SaveSettings, null,onSchange);
            }
            else
            {
                onSchange();
            }
        }
    }
    //增加一条设置
    function AddSetting()
    {   
        if(document.getElementById('settingTable') != null)
        {
            document.getElementById('btnAddKind').disabled= true ;
            document.getElementById('btnSaveKind').disabled= true ;
            var table = document.getElementById('settingTable');     
            var newTr = table.insertRow();

            var newcell = newTr.insertCell();
            newcell.style.textAlign = "right";
            newcell.style.paddingRight = "5px";
            newcell.innerHTML = "<input id='newClassName' maxLength=4 style='text-align:left;border:solid #a5a5a5 1px;width:80px;' onkeypress='return event.keyCode>=48&&event.keyCode<=57;' onpaste='return false;' ondragenter='return false;'   value='<请输入分数>'  onblur=\"AddOne(this)\" \>";

            
            newcell = newTr.insertCell();
            newcell.style.textAlign = "right";
            newcell.style.paddingRight = "5px";
//            newcell.innerText = "100";
            
            newcell = newTr.insertCell();
            newcell.style.textAlign = "center";
//            newcell.innerHTML = "<img src='../../Common/images/delete_icon.gif' alt='删除此项' class='imageBtnStyle' onclick='DelClass(this.parentElement.parentElement);' />";
            document.getElementById('newClassName').select();

        }
        else
        {
//            showMassgeBox("提示","请您先选择要添加的年级",1,null);
            return -1;
        }
        return 1;
    }
    
    function AddOne(obj)
    {
        var settingName = obj.value.Trim();
        var rowIndex = obj.parentElement.parentElement.rowIndex;

        var settingTable = document.getElementById('settingTable');
        var minscore = 0;
        if(settingName == null || settingName.length == 0 || settingName == '<请输入分数>' || ( /\D/.test(settingName)))
        {        
            settingTable.deleteRow(rowIndex);
        }
        else
        {
            settingTable.rows(rowIndex).id = "null";
            settingTable.rows(rowIndex).objmax = parseInt(settingName);
            
            if(parseInt(settingName)>10)
            {
                minscore = parseInt(settingName)-10;
            }
            settingTable.rows(rowIndex).objmin = minscore;
            settingTable.rows(rowIndex).cells(0).innerHTML = "<input maxlength='4' class='txtStyle' style='text-align: right; border-left: 0px; width:80px;border-top: 0px; border-right: 0px; border-bottom: 0px;'  value='"+settingName+"' oldvalue='"+settingName+"' onkeypress='return event.keyCode>=48&&event.keyCode<=57;' onpaste='return false;' ondragenter='return false;'  onfocusout='optionSettingScoremax(this)' onclick='modi(this)' readonly />";
       
            settingTable.rows(rowIndex).cells(1).innerHTML = "<input maxlength='4' class='txtStyle' style='text-align: right; border-left: 0px; width:80px;border-top: 0px; border-right: 0px; border-bottom: 0px;'  value='"+minscore+"' oldvalue='"+minscore+"' onkeypress='return event.keyCode>=48&&event.keyCode<=57;' onpaste='return false;' ondragenter='return false;'  onfocusout='optionSettingScoremin(this)' onclick='modi(this)' readonly />";
    
            settingTable.rows(rowIndex).cells(2).innerHTML = "<img style='cursor:hand' src='../../Common/images/delete_icon.gif' alt='删除此项' class='imageBtnStyle' onclick='DelSetting(this.parentElement.parentElement);' />";
            settingChange = true;
        }


        document.getElementById('btnAddKind').disabled= false ;
        document.getElementById('btnSaveKind').disabled= false ;
    }

    //焦点移开后判断更新
    function optionSettingScoremax(obj)
    {
        s=true;
        var id = obj.parentElement.parentElement.id;
        var value = obj.value;

        if(value.length == 0 ||  ( /\D/.test(value)))
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
            settingChange = true;
        }
        unModi(obj,'right');
        obj.parentElement.parentElement.objmax = obj.value;
    }
        //焦点移开后判断更新
    function optionSettingScoremin(obj)
    {
        s=true;
        var id = obj.parentElement.parentElement.id;
        var value = obj.value;

        if(value.length == 0 ||  ( /\D/.test(value)))
        {   
            obj.setAttribute("value",obj.getAttribute("oldvalue")); 
        }
        else
        {
            obj.setAttribute("oldvalue",value); 
            settingChange = true;
        }
        unModi(obj,'right');
        obj.parentElement.parentElement.objmin = obj.value;
    }
    //非编辑状态
    function unModi(obj,align)
    {
        if(obj.readOnly == false)
        {
            obj.parentElement.style.textAlign = align;
           obj.style.textAlign = align;  
           obj.style.border = 'solid #ffffff 1px;';   
           obj.readOnly = true; 
           updateActivate = 0;   
        }
    }
    //编辑状态
    function modi(obj)
    { 
        if( obj.readOnly == true)
        {
         //   obj.parentElement.style.textAlign = 'center';
            obj.style.textAlign = 'left';  
            obj.style.border = 'solid #a5a5a5 1px;';   
            obj.readOnly = false;   
            obj.select();
            updateActivate = 1; 
        }
    } 
    var currentObj = null;
    function SetHightLight(obj)
    {
         if(currentObj!=null)
            currentObj.style.backgroundColor = "#ffffff";
         obj.style.backgroundColor = "#fffccf";
         currentObj = obj;
    }
    //被删除的项目
    var delArray = new Array();
    function DelSetting(obj)
    {
        if(obj.id != "null")
        {
            delArray[ delArray.length]=obj.id;
        }
        settingChange = true;
        var settingTable = document.getElementById('settingTable');
        for(i=1;i<settingTable.rows.length;i++)
        {
            if(obj == settingTable.rows[i])
            {
                settingTable.deleteRow(i);
                break;
            }
        }
        
    }
    function OnselectChange(obj,value)
    {
        obj.parentElement.parentElement.objop =value;
        settingChange = true;
    }
    function SaveSettings()
    {
    
        var settingTable = document.getElementById('settingTable');
        if(settingTable==null)
            return;
        var arraytemp = new Array();
        var typeid = document.getElementById('typeid');
        var examid = document.getElementById('examid');
        var classtype = document.getElementById('classtype');
        var grade = document.getElementById('grade');
        for(i=1;i<settingTable.rows.length;i++)
        {
            arraytemp[i-1] = {"RID":(settingTable.rows[i].id=="null"?-1:settingTable.rows[i].id),
                                "ExamID":examid.value,
                                "SubjectID":typeid.value,
                                "Max":settingTable.rows[i].objmax,
                                "Min":settingTable.rows[i].objmin,
                                "Grade":grade.value
                                };
        }
        
        PageMethods.SaveUsersSets(arraytemp,delArray,examid.value,typeid.value,classtype.value,function(result){
            for(i=0;i<result.length;i++)
            {
                settingTable.rows[i+1].id = result[i];
            }
            settingChange = false;
            showMassgeBox("提示","保存完成",1,doThis);
        },function(err){showMassgeBox("提示","err._message",1,doThis);});
    }
</script>
</head>
<body>
 <form id="form1" runat="server">
<div class="mainWarp">
    <div class="pageBody">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
     </asp:ScriptManager>
         <div style=" height:200px;">
            科目：<select id="subjectSelect" style="width: 68px" onchange="onSubjectSelect(this.selectedIndex)">
            </select>
            <input type="button" class="commonBut" id="btnAddKind" value="新增" onclick="AddSetting()" />
            <input type="button" class="commonBut" id="btnSaveKind" value="保存" onclick="SaveSettings()" />
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                        <ContentTemplate>
                <asp:Repeater ID="Repeater1" runat="server">
                    <HeaderTemplate>
                        <div style="overflow-y:auto;overflow-x:none;height:98%;">
                        <table id="settingTable" border="0" cellpadding="0" cellspacing="1" style="width: 95%;"
                            class="useList">
                            <tr>
                                <th width="25%" style="text-align: right; padding-right: 5px;">
                                    上限</th>
                                <th width="25%" style="text-align: right; padding-right: 5px;">
                                    下限
                                </th>
                                <th width="25%" style="text-align: center;">
                                    删除
                                </th>
                            </tr>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr style="background-color: White;" id="<%# Eval("RID")%>" 
                            objmax="<%# Eval("Max")  %>" objmin="<%# Eval("Min")%>">
                            <td style="text-align: right; padding-right: 5px;">
                                <%--onkeyup="if(/\D/.test(this.value)){this.value=this.oldvalue;}"--%>
                                <input onkeypress="return event.keyCode>=48&&event.keyCode<=57" onpaste="return false;"
                                    ondragenter="return false" maxlength="4" class="txtStyle" style='text-align: right;
                                    border-left: 0px; width: 80px; border-top: 0px; border-right: 0px; border-bottom: 0px;'
                                    id="Text2" value="<%# Eval("Max")%>" oldvalue="<%# Eval("Max")%>"
                                    onfocusout="optionSettingScoremax(this)" onclick="modi(this)" readonly />
                             </td>
                            <td style="text-align: right; padding-right: 5px;">
                                <%--onkeyup="if(/\D/.test(this.value)){this.value=this.oldvalue;}"--%>
                                <input onkeypress="return event.keyCode>=48&&event.keyCode<=57" onpaste="return false;"
                                    ondragenter="return false" maxlength="4" class="txtStyle" style='text-align: right;
                                    border-left: 0px; width: 80px; border-top: 0px; border-right: 0px; border-bottom: 0px;'
                                    id="Text1" value="<%# Eval("Min")%>" oldvalue="<%# Eval("Min")%>"
                                    onfocusout="optionSettingScoremin(this)" onclick="modi(this)" readonly />
                             </td>
                            <td style="text-align: center;">
                                <img style='cursor:hand' src="../../Common/images/delete_icon.gif" alt="删除此项" class="imageBtnStyle" onclick="DelSetting(this.parentElement.parentElement);" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </table></div>
                    </FooterTemplate>
                </asp:Repeater>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
            </Triggers>
            </asp:UpdatePanel>
        </div>
         <div style="display: none;">
            <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
            <asp:TextBox ID="typeid" runat="server"></asp:TextBox><asp:TextBox ID="examid" runat="server"></asp:TextBox><asp:TextBox ID="classtype" runat="server"></asp:TextBox><asp:TextBox ID="grade" runat="server"></asp:TextBox>
        </div>
    </div>
</div>
    </form>

<script type="text/javascript">
<%
    if(subj!=null)
    {
        Response.Write("var oOption;var subjectSelect = document.getElementById('subjectSelect');var typeid = document.getElementById('typeid');var btnBind = document.getElementById('btnBind');");
        foreach (Meqs.Entity.ExamSubjecySchool2 ese2 in subj)
        {
            string name = this.Server.HtmlDecode(ese2.SubjectName);
            name = name.Replace("\\", "\\\\");
            name = name.Replace("'", "\\'");
            name = name.Replace("<", "\\<");
            name = name.Replace(">", "\\>");

            string strid = this.Server.HtmlDecode(ese2.SubjectID.ToString());
            strid = strid.Replace("\\", "\\\\");
            strid = strid.Replace("'", "\\'");
            strid = strid.Replace("<", "\\<");
            strid = strid.Replace(">", "\\>");
            Response.Write("oOption = document.createElement(\"OPTION\");");
            Response.Write("oOption.text ='" + name + "';");
            Response.Write("oOption.value ='" + strid + "';");
            Response.Write("subjectSelect.add(oOption);");
        }
        Response.Write("var oOption1 = document.createElement(\"OPTION\");");
        Response.Write("oOption1.text ='总分';");
        Response.Write("oOption1.value ='0';");
        Response.Write("subjectSelect.add(oOption1);subjectSelect.options[subjectSelect.options.length-1].selected=true;");
        Response.Write("typeid.value =0;");
        if(subj.Count>0)
        {
           Response.Write("btnBind.click();"); 
        }
    }
 %>
</script>


</body>
</html>
